package com.tiberio.movil.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import com.tiberio.movil.R;
import com.tiberio.movil.entity.PlayerInfoEntity;
import com.tiberio.movil.entity.ServerInfoEntity;
import com.tiberio.movil.servicio.ServicioHttp;

public class MainActivity extends Activity{

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        
       ServicioHttp servicioHttp= ServicioHttp.getInstance();
        //TODO: poner loading
        
        
        //TODO: quitar la gestion con 1's
        ServerInfoEntity serverInfo = servicioHttp.conectar(0);
        
        if(serverInfo != null)
        {
            /*PlayerInfoEntity pie = servicioHttp.getPlayerInfo();
            if(pie != null)
            {*/
                Intent myIntent= new Intent(MainActivity.this, Principal.class);
                startActivity(myIntent);
            /*}
            else
            {
                TextView t = (TextView)findViewById(R.id.tv);
                t.setText("Error al conectar con el servidor.");
                setContentView(t);
            }    */
        }
        else
        {
             TextView t = (TextView)findViewById(R.id.tv);
             t.setText("Error al conectar con el servidor.");
             setContentView(t);
        }
               
        






    }
    
    /**
     * super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TextView t = (TextView)findViewById(R.id.tv);
        
      try{  ServicioHttp servHttp = new ServicioHttp();
        //TODO: quitar la gestion con 1's
        ServerInfoEntity serverInfo = servHttp.conectar(1);
        
        if(serverInfo != null)
        {
            t.setText("ok!");
        }
        else
            t.setText("fallo");          
        }catch(Throwable th)
        {
            Log.e("ERROR", "Error:", th);
            t.setText(th.getMessage());
        }
     */
}
